home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1993 / MacHack 1993.toast / MacHack™ 1987-1992 / MacHack™ '90 / Other Stuff / Demos ƒ / TOPS SoftTalk Package / STClient ƒ / CSTClientApp.c next >
Encoding:
C/C++ Source or Header  |  1989-09-08  |  7.3 KB  |  368 lines  |  [TEXT/MPS ]

  1. /*
  2. ------------------------------------------------------------------------------
  3. |    Sun Microsystems, TOPS Division
  4. |    950 Marina Village Parkway
  5. |    P.O. Box 4016
  6. |    Alameda, CA 94501
  7. |    
  8. |    Copyright (c) 1989 Sun Microsystems, Inc. All rights reserved.
  9. |    
  10. |    Sun considers its source code as an unpublished, proprietary trade secret,
  11. |    and it is available only under strict license provisions. This copyright
  12. |    notice is placed here only to protect Sun in the event the source is deemed
  13. |    a published work. Disassembly, decompilation, or other means of reducing the
  14. |    object code to human readable form is prohibited by the license agreement
  15. |    under which this code is provided to the user or company in possession of
  16. |    this copy.
  17. |    
  18. |    RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the Government
  19. |    is subject to restrictions as set forth in subparagraph (c) (1) (ii) of the
  20. |    Rights in Technical Data and Computer Software clause at DFARS 52.227-7013
  21. |    and in similar clauses in the FAR and NASA FAR supplement.
  22. ------------------------------------------------------------------------------
  23. */
  24.  
  25.  
  26.  
  27.  
  28. /*
  29.  
  30.     IMPLEMENTATION CSTClientApp
  31.  
  32. */
  33.  
  34. #include "CSTClientApp.h"
  35.  
  36.  
  37. /*** constants  ***/
  38. #define    kNumLines (25)
  39. #define    kWindowWidth (400)
  40. #define    kTop    (50)
  41. #define    kLeft    (10)
  42.  
  43. /* menu STUFF */
  44. #define    iClearWindow    (1)
  45. #define    iDebugger    (2)
  46. #define    iQuit    (3)
  47.  
  48. #define    mClient    (mEdit+1)
  49. #define    iCreateClient    (1)
  50. #define    iDestroyClient    (2)
  51. #define    iFunction1    (4)
  52. #define    iFunction2    (5)
  53. #define    iFunction3    (6)
  54. #define    iFunction4    (7)
  55. #define    iFunction5    (8)
  56.  
  57. /* cmd numbers */
  58. #define    cClearWindow    (1000)
  59. #define    cDebugger    (1008)
  60. #define    cCreateClient    (1001)
  61. #define    cDestroyClient    (1002)
  62. #define    cFunction1    (1003)
  63. #define    cFunction2    (1004)
  64. #define    cFunction3    (1005)
  65. #define    cFunction4    (1006)
  66. #define    cFunction5    (1007)
  67.  
  68.  
  69.  
  70. /***  METHODS for CSTClientApp  ***/
  71. void CSTClientApp::ISTClientApp(void) {
  72.     this->IApplication('????');
  73.     this->CreateWindow();
  74. }
  75.  
  76. void CSTClientApp::CreateWindow(void) {
  77.     Point p;
  78.     CWriteLnWindow* w = new(CWriteLnWindow);
  79.  
  80.     p.h = kLeft;
  81.     p.v = kTop;
  82.     w->IWriteLnWindow((unsigned char *)"\pClient Window", kNumLines, kWindowWidth, p);
  83.     fWindow = w;
  84.     /* fClient = NIL; */
  85. }
  86.  
  87. void CSTClientApp::CreateMenus(void) {
  88.     char appleString[2];
  89.     appleString[0] = 0x1;
  90.     appleString[1] = appleMark;
  91.     fAppleMenu = NewMenu(mApple, appleString);
  92.     AppendMenu(fAppleMenu, "\pAbout Client...;(-");
  93.     AddResMenu(fAppleMenu, 'DRVR');
  94.     InsertMenu(fAppleMenu, 0);
  95.  
  96.     fFileMenu = NewMenu(mFile, "\pFile");
  97.     AppendMenu(fFileMenu, "\pClear Window/W;Debugger/M;Quit/Q");
  98.     InsertMenu(fFileMenu, 0);
  99.  
  100.     fEditMenu = NewMenu(mEdit, "\pEdit");
  101.     AppendMenu(fEditMenu, "\pCut/X;Copy/C;Paste/V");
  102.     InsertMenu(fEditMenu, 0);
  103.  
  104.     fClientMenu = NewMenu(mClient, "\pClient");
  105.     AppendMenu(fClientMenu, "\pOpen/C;Close/D;(-;Function1/1;Function2/2;Function3/3;Function4/4;Function5/5");
  106.     InsertMenu(fClientMenu, 0);
  107.  
  108.     DrawMenuBar();
  109. }
  110.  
  111. void CSTClientApp::CreateClient(void) {
  112.     INT32 err;
  113.     Str255 msg;
  114.  
  115.      err = STClientCreate();
  116.     fWindow->WriteLn((unsigned char*)"\pTried to open client.  result Code: ");
  117.     NumToString(err,msg);
  118.     fWindow->WriteLn(msg);
  119.     if (err != noErr) {
  120.         SysBeep(1);
  121.         fWindow->WriteLn((unsigned char*)"\pCould not open client. :-(");
  122.         return;
  123.         }
  124.     fWindow->NewLine();
  125.     fWindow->NewLine();
  126. }
  127.  
  128. void CSTClientApp::DestroyClient(void) {
  129.     INT32 err;
  130.     Str255 msg;
  131.  
  132.      err = STClientDispose();
  133.     NumToString(err,msg);
  134.     fWindow->WriteLn(msg);
  135.     if (err != noErr) {
  136.         SysBeep(1);
  137.         fWindow->WriteLn((unsigned char*)"\pCould not dispose client. :-(");
  138.         return;
  139.         }
  140.     fWindow->WriteLn((unsigned char*)"\pSuccessfully destroyed client.");
  141.     fWindow->NewLine();
  142.     fWindow->NewLine();
  143. }
  144.  
  145.  
  146.  
  147. void CSTClientApp::CallFunction1(void) {
  148.     INT32 err;
  149.     Str255 msg;
  150.  
  151.     err = Func1();
  152.     fWindow->WriteLn((unsigned char*)"\p==> Func1:  result Code = ");
  153.     NumToString(err,msg);
  154.     fWindow->WriteLn(msg);
  155.     fWindow->NewLine();
  156.     fWindow->NewLine();
  157. }
  158.  
  159. void CSTClientApp::CallFunction2(void) {
  160.     INT32 err;
  161.     Str255 msg;
  162.     static INT32 arg = 0L;
  163.  
  164.     arg++;
  165.     err = Func2(arg);
  166.     fWindow->WriteLn((unsigned char*)"\p==> Func2:  result Code = ");
  167.     NumToString(err,msg);
  168.     fWindow->WriteLn(msg);
  169.     fWindow->NewLine();
  170.     fWindow->NewLine();
  171. }
  172.  
  173. void CSTClientApp::CallFunction3(void) {
  174.     INT32 err;
  175.     Str255 msg;
  176.     static INT32 arg1 = 0;
  177.     static INT16 arg2 = 20;
  178.  
  179.     arg1++;
  180.     arg2++;
  181.     err = Func3(arg1,arg2);
  182.     fWindow->WriteLn((unsigned char*)"\p==> Func3:  result Code = ");
  183.     NumToString(err,msg);
  184.     fWindow->WriteLn(msg);
  185.     fWindow->NewLine();
  186.     fWindow->NewLine();
  187. }
  188.  
  189. void CSTClientApp::CallFunction4(void) {
  190.     INT32 err;
  191.     Str255 msg;
  192.     char* arg = "hello out there";
  193.  
  194.     err = Func4(arg);
  195.     fWindow->WriteLn((unsigned char*)"\p==> Func4:  result Code = ");
  196.     NumToString(err,msg);
  197.     fWindow->WriteLn(msg);
  198.     fWindow->NewLine();
  199.     fWindow->NewLine();
  200. }
  201.  
  202. void CSTClientApp::CallFunction5(void) {
  203.     INT32 err;
  204.     Str255 msg;
  205.     Str255 pStr = (unsigned char*)"\pnever say never";
  206.  
  207.     err = Func5(pStr);
  208.     fWindow->WriteLn((unsigned char*)"\p==> Func5:  result Code = ");
  209.     NumToString(err,msg);
  210.     fWindow->WriteLn(msg);
  211.     fWindow->NewLine();
  212.     fWindow->NewLine();
  213. }
  214.  
  215.  
  216.  
  217. INT16 CSTClientApp::MenuSelectionToCmd(INT16 menu, INT16 item) {
  218.     INT16 returnValue = cNoCmd;
  219.  
  220.     switch (menu) {
  221.         case mFile:
  222.             switch(item) {
  223.                 case iClearWindow:
  224.                     returnValue = cClearWindow;
  225.                     break;
  226.                 
  227.                 case iDebugger:
  228.                     returnValue = cDebugger;
  229.                     break;
  230.                 
  231.                 case iQuit:
  232.                     returnValue = cQuit;
  233.                     break;
  234.                 }
  235.             break;
  236.         
  237.         case mClient:
  238.             switch(item) {
  239.                 case iCreateClient:
  240.                     returnValue = cCreateClient;
  241.                     break;
  242.                 
  243.                 case iDestroyClient:
  244.                     returnValue = cDestroyClient;
  245.                     break;
  246.                 
  247.                 case iFunction1:
  248.                     returnValue = cFunction1;
  249.                     break;
  250.                 
  251.                 case iFunction2:
  252.                     returnValue = cFunction2;
  253.                     break;
  254.                 
  255.                 case iFunction3:
  256.                     returnValue = cFunction3;
  257.                     break;
  258.                 
  259.                 case iFunction4:
  260.                     returnValue = cFunction4;
  261.                     break;
  262.                 
  263.                 case iFunction5:
  264.                     returnValue = cFunction5;
  265.                     break;
  266.                 
  267.                 }
  268.                 break;
  269.         
  270.         default:
  271.             returnValue = inherited::MenuSelectionToCmd(menu,item);
  272.         }
  273.     
  274.     return(returnValue);
  275. }
  276.  
  277.  
  278. void CSTClientApp::DoMenuCmd(INT16 cmd) {
  279.     switch (cmd) {
  280.         case cClearWindow:
  281.             this->DoClear();
  282.             break;
  283.         
  284.         case cDebugger:
  285.             this->DoDebugger();
  286.             break;
  287.  
  288.         case cCreateClient:
  289.             this->DoCreateClient();
  290.             break;
  291.  
  292.         case cDestroyClient:
  293.             this->DoDestroyClient();
  294.             break;
  295.             
  296.         case cFunction1:
  297.             this->DoFunction1();
  298.             break;
  299.             
  300.         case cFunction2:
  301.             this->DoFunction2();
  302.             break;
  303.             
  304.         case cFunction3:
  305.             this->DoFunction3();
  306.             break;
  307.             
  308.         case cFunction4:
  309.             this->DoFunction4();
  310.             break;
  311.             
  312.         case cFunction5:
  313.             this->DoFunction5();
  314.             break;
  315.             
  316.         default:
  317.             inherited::DoMenuCmd(cmd);
  318.             break;
  319.         }
  320. }
  321.  
  322.  
  323. /** menu actions **/
  324. void CSTClientApp::Quit(void) {
  325.     this->DestroyClient();
  326.     inherited::Quit();
  327. }
  328.  
  329. void CSTClientApp::DoClear(void) {
  330.     fWindow->ClearContents();
  331.     fWindow->Invalidate();
  332. }
  333.  
  334. void CSTClientApp::DoDebugger(void) {
  335.     Debugger();
  336. }
  337.  
  338. void CSTClientApp::DoCreateClient(void) {
  339.     this->CreateClient();
  340. }
  341.  
  342. void CSTClientApp::DoDestroyClient(void) {
  343.     this->DestroyClient();
  344. }
  345.  
  346. void CSTClientApp::DoFunction1(void) {
  347.     this->CallFunction1();
  348. }
  349.  
  350. void CSTClientApp::DoFunction2(void) {
  351.     this->CallFunction2();
  352. }
  353.  
  354. void CSTClientApp::DoFunction3(void) {
  355.     this->CallFunction3();
  356. }
  357.  
  358. void CSTClientApp::DoFunction4(void) {
  359.     this->CallFunction4();
  360. }
  361.  
  362. void CSTClientApp::DoFunction5(void) {
  363.     this->CallFunction5();
  364. }
  365.  
  366.  
  367.  
  368.